<!-- 企业管理 - 企业账户管理-->
<template>
  <div>
    <Add ref="add" @ok="search"></Add>
    <ZgNewPage
      ref="page"
      title="企业账户管理"
      :showInlineBtn="false"
      :uniqueName="uniqueName"
      :pageOpt="pageOpt"
      :dataBtns="dataBtns"
      :extraBtns="extraBtns"
      :headers="headers"
      :conditions="conditions"
      :adminWidth="250"
      :scrollX="1500"
      @search="onSearch"
      @filter="onFilter"
      @header="mergeHeader"
      @admin="toAdmin"
      @extra="toExtra"
    >
      <template slot="columns">
        <a-table-column
          v-for="(h, i) in headers"
          :key="`column${i}`"
          :width="h.width === 0 ? 'auto' : h.width"
          align="center"
          :title="h.label"
        >
          <template slot-scope="record">
            <template v-if="h.code === 'F' || h.code === 'G'">
              <ZgSwitch v-model="record[h.code]"></ZgSwitch>
            </template>
            <template v-else>{{ record[h.code] }}</template>
          </template>
        </a-table-column>
      </template>
      <template slot="thMode" slot-scope="scope">
        <a-row :gutter="10">
          <a-col :span="4" v-for="t in scope.list" :key="`thMode_${t.id}`">
            <a-card class="mb10">
              <div class="wfull h100 scroll">
                {{ t }}
              </div>
            </a-card>
          </a-col>
        </a-row>
      </template>
    </ZgNewPage>
  </div>
</template>
<script>
const accountTypeArr = [
  { value: '1', label: '入金账户' },
  { value: '2', label: '提现账户' },
  { value: '3', label: '出金账户' },
  { value: '4', label: '监管账户' }
]
export default {
  components: {
    Add: () => import('./Add.vue')
  },
  data() {
    return {
      uniqueName: 'test',
      pageOpt: {
        showConditionBtn: true,
        showHeaderConfig: true,
        showPageTitle: true
      },
      conditions: [
        {
          code: 'name',
          compType: '单行文本',
          label: '机构名称',
          defaultVal: '',
          extra: { placeholder: '请输入机构名称' }
        },
        {
          code: 'accountNum',
          compType: '单行文本',
          label: '银行账号',
          defaultVal: '',
          extra: { placeholder: '请输入银行账号' }
        },
        { code: 'creatTime', compType: '日期时间', label: '创建时间', defaultVal: '' },
        {
          code: 'account',
          compType: '开关',
          label: '默认账户',
          defaultVal: ''
        },
        {
          code: 'select',
          compType: '下拉选择',
          label: '账户类型',
          defaultVal: '',
          extra: { 下拉选项: accountTypeArr }
        }
      ],
      headers: [
        { code: 'A', label: '机构名称', width: 200, isShow: true, sort: 0 },
        { code: 'B', label: '账户号', isShow: true, sort: 0 },
        { code: 'C', label: '金融机构', width: 220, isShow: true, sort: 0 },
        { code: 'D', label: '账户类型', width: 130, isShow: true, sort: 0 },
        { code: 'E', label: '余额', isShow: true, width: 130, sort: 0 },
        { code: 'F', label: '是否默认账户', width: 150, isShow: true, sort: 0 },
        { code: 'G', label: '状态', width: 130, isShow: true, sort: 0 }
      ],
      dataBtns: [
        {
          key: 1,
          name: '余额更新',
          type: 'link',
          isShow: () => {
            return true
          }
        },
        {
          key: 2,
          name: '编辑',
          type: 'link',
          isShow: () => {
            return true
          }
        },
        {
          key: 3,
          name: '删除',
          type: 'link',
          isShow: () => {
            return true
          }
        }
      ],
      extraBtns: [{ key: 1, name: '新增', icon: 'plus-circle', type: 'primary' }]
    }
  },
  methods: {
    search() {
      this.$refs.page.search()
    },
    onSearch(param) {
      const diyHeaders = localStorage.getItem(this.currentUser.username + '_diyHeader_' + this.uniqueName)
      if (diyHeaders) {
        this.mergeHeader(JSON.parse(diyHeaders))
      }
      // 加载表头
      const list = [
        {
          key: '1',
          id: '1',
          A: '孝义市中惠煤业有限责任公司',
          B: '999999000000',
          C: '太原农村商业银行股份有限公司',
          D: '入金账户',
          E: '',
          F: false,
          G: false,
          isUse: true
        },
        {
          key: '2',
          id: '2',
          A: '山西焦煤集团有限责任公司',
          B: '16544616132645646',
          C: '太原农村商业银行股份有限公司',
          D: '提现账户',
          E: '',
          F: true,
          G: true,
          isUse: true
        },
        {
          key: '3',
          id: '3',
          A: '孝义市中惠煤业有限责任公司',
          B: '454616646461',
          C: '太原农村商业银行股份有限公司',
          D: '入金账户',
          E: '',
          F: false,
          G: false,
          isUse: true
        }
      ]
      this.$refs.page.endSearch({
        total: list.length,
        list: list
      })
    },
    onFilter(f, param) {},
    toAdmin(param) {
      if (param.key === 1) {
        alert('余额更新')
      } else if (param.key === 2) {
        this.$refs.add.open({}, 'edit')
      } else if (param.key === 3) {
        this.confirm(() => {
          // this.$http.post('/zg-system/attach/del', [param.obj.id], () => {
          //   this.$refs.page.search()
          // })
        }, '确定要删除这条数据么')
      }
    },
    toExtra(opt) {
      this.$refs.add.open()
    },
    mergeHeader(newHeaders) {
      if (!newHeaders) {
        return
      }
      this.headers = newHeaders
        .filter((t) => {
          return t.isShow
        })
        .sort((a, b) => {
          return a.sort - b.sort
        })
    }
  }
}
</script>

<style lang="scss" scoped></style>
